package com.yeung.springcloud.entities.com.yeung.springcloud.service;

import com.yeung.springcloud.entities.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class DeptClientServiceFallbackFactroy implements FallbackFactory<DeptClientService> {
    /**
     * 针对整个DeptClientService的各个方法的各种异常来创建熔断, 降低代码耦合性, 侵染性, 不在在原生代码中去针对
     * 每个业务方法创建熔断fallback方法
     *
     * @param throwable
     * @return
     */
    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public boolean add(Dept dept) {
                return false;
            }

            @Override
            public Dept get(Long id) {
                return new Dept().setDeptno(id).setDname("该ID" + id + "没有对应的信息").setDb_source("no this database in Mysql");
            }

            @Override
            public List<Dept> list() {
                return new ArrayList<>();
            }
        };
    }
}
